package day1;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2022/12/26  17:55
 */
public class Solution {
    public static void main(String[] args) {
        System.out.println(sqrt(25));
    }

    /**
    回文判断
     */
    public static boolean judge (String str) {
        if (str.length() == 0 || str.equals("")) {
            return false;
        }
        int i = 0;
        int j = str.length() - 1;
        while (i <= j) {
            if (str.charAt(i) != str.charAt(j)) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }

    /**
     * 求平方根
     */
    public static int sqrt (int x) {
        // write code here
        if (x <= 1) {
            return x;
        }
        int left = 0;
        int right = x;
        int result = 0;
        while (left <= right) {
            int mid = left + (right - left) / 2;

            if (mid <= x / mid) {
                result = mid;
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return result;
    }
}

